package com.easy;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by Lxk on 2019/8/11.
 */
public class Solution453 {

    //核心思想是通过增量相等来列方程，最小的数字全程增加，假设最终一致的数字为k,所以有
    //(k-min(nums))*(nums.length-1) = k*nums.length - sum(nums)
    public int minMoves(int[] nums) {
        int res = 0;
        if (nums == null || nums.length == 0) {
            return res;
        }
        List<Integer> data = new ArrayList<>();
        int sum = 0;
        for (int val : nums) {
            sum += val;
            data.add(val);
        }
        Collections.sort(data);
        res = sum - data.get(0) * (nums.length - 1) - data.get(0);
        return res;
    }

}
